<template>
  <!--核销选择页面-->
  <div>
    <p><img src="../../assets/banner.png" alt="" width="100%"></p>
    <p class="title">会员尊享服务类型</p>
    <ul class="chooseway">
      <li v-for="(item,index) in employeeServerList" :key="item.index">
        <div class="radio-box">
          <label>{{item.serverName}}</label>
          <span class="radio" :class="{'on':item.isChecked}"></span>
          <input :value="item.index" class="input-radio" :checked='item.isChecked' @click="check(index)" type="radio" :id="item.index">
        </div>
      </li>
    </ul>
    <wv-group title="次数" class="cishu">
      <wv-cell
        title="次数"
        is-link
        :value="chooseNum | chooseNumFilter"
        @click.native="chooseNumPickerShow = true"
      />
      <wv-picker
        :visible.sync="chooseNumPickerShow"
        v-model="chooseNum"
        :columns="chooseNumColumns"
        @confirm="confirmchooseNum"
      />
    </wv-group>
    <wv-group title="备注" class="beizhus">
      <wv-textarea placeholder="请输入备注" :rows="6" show-counter max-length="500" v-model="addcheckrecord.remark"></wv-textarea>
    </wv-group>
    <p class="offer" @click="isVisible=true">使用补录</p>
    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../assets/close.png" alt="" width="15" @click="isVisible=false">
        请确认选择的会员尊享服务类 型是否正确，补录后将无法更改。
        <p class="btn">
          <button @click="submitInfo()">确定</button>
          <button @click="isVisible=false">取消</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getEmployeeCancheck, addCheckDataSub} from '../../../test/unit/http'
  import {Toast} from 'we-vue'
  export default {
    name: '',
    props: {},
    data() {
      return {
        employeeServerList: [],
        chooseNum: ['1'],
        chooseNumPickerShow: false,
        chooseNumColumns: [
          {
            values: ['1', '2',],
            defaultIndex: 0
          }
        ],
        isVisible: false,
        addcheckrecord: {},
        isTakePeople:2
      };
    },
    methods: {
      getEmployeeCancheckData(params){
        getEmployeeCancheck(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            let employeeServerList = res.object.employeeServerList;
            let isTakePeople = res.object.isTakePeople;
            this.isTakePeople=isTakePeople;
            for (let key in employeeServerList) {
              if (key == 0) {
                employeeServerList[key]['isChecked'] = true;
                let employeeServer = employeeServerList[key];
                this.addcheckrecord['checkType'] = employeeServer.serverType;
                this.addcheckrecord['serverName'] = employeeServer.serverName;
                this.addcheckrecord['serverId'] = employeeServer.serverId;
              } else {
                employeeServerList[key]['isChecked'] = false;
              }
            }
            this.employeeServerList = employeeServerList;
          }
        })
      },
      goSubCheck(params){
        addCheckDataSub(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.push({path: 'addchecksuccess'});
          } else {
            Toast.fail(res.info)
          }

        })
      },
      check(index) {
        // 先取消所有选中项
        this.employeeServerList.forEach((item) => {
          item.isChecked = false;
        });
        //再设置当前点击项选中
        console.log(this.employeeServerList[index]);
        //设置值，以供传递
        this.employeeServerList[index].isChecked = true;
        let employeeServer = this.employeeServerList[index];
        this.addcheckrecord['checkType'] = employeeServer.serverType;
        this.addcheckrecord['serverName'] = employeeServer.serverName;
        this.addcheckrecord['serverId'] = employeeServer.serverId;
        this.addcheckrecord['optType'] = 1;//使用
      },
      confirmchooseNum (picker) {
        this.chooseNum = picker.getValues()
      },
      submitInfo(){
        let accountGoodsId = this.$route.query.accountGoodsId;
        this.addcheckrecord['useNum'] = this.chooseNum[0];
        this.addcheckrecord['accountGoodsId'] = accountGoodsId;
        this.goSubCheck(this.addcheckrecord);
      }
    },
    created() {
      let params = {serverType: 1};
      this.getEmployeeCancheckData(params);
    },
    filters: {
      chooseNumFilter (val) {
        if (Array.isArray(val)) {
          return val.toString()
        } else {
          return '请选择'
        }
      }
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .beizhus{
    padding-bottom: 60px;
  }
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;
    img {
      position: absolute;
      right: 10px;
      top: 10px
    }
    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }
      :last-child {
        background-color: #ccc;
      }
      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }

  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #f98e3c;
    height: 50px;
    line-height: 50px;
    color: #fff;
  }

  .title {
    font-size: 20px;
    color: #111;
    font-weight: 700;
    text-align: left;
    padding: 10px;
  }

  .chooseway {
    li {
      border-bottom: 1px solid #eee;
      padding: 10px 0;
      margin: 10px;
    }
    :last-child {
      border-bottom: none;
    }
  }

  .radio-box {
    position: relative;
    height: 25px;
    line-height: 25px;
    font-size: 15px;
    color: #111;
    text-align: left;
    display: flex;
    label {
      flex: 1;
    }
    img {
      vertical-align: middle;
      margin-right: 10px;
    }
    .input-radio {
      display: inline-block;
      position: absolute;
      opacity: 0;
      width: 25px;
      height: 25px;
      cursor: pointer;
      right: 0;
      top: 0;
      outline: none;
      -webkit-appearance: none;
    }
  }

  .radio {
    display: inline-block;
    width: 25px;
    height: 25px;
    vertical-align: middle;
    cursor: pointer;
    background: url(../../assets/radio.png) no-repeat;
    background-size: 100% 100%;

  }

  .on {
    background-image: url(../../assets/cheaked.png);
    background-size: 100% 100%;
  }
</style>
